package com.example.flshtarvel.service;

import com.example.flshtarvel.entity.ArticleLikeMap;
import com.example.flshtarvel.entity.Collect;
import com.example.flshtarvel.entity.Like;
import com.example.flshtarvel.entity.RouteLikeMap;
import com.example.flshtarvel.mapper.ArticleLikeMapMapper;
import com.example.flshtarvel.mapper.LikeMapper;
import com.example.flshtarvel.mapper.RouteLikeMapMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LikeService {
//    @Autowired(required = false)
//    RouteLikeMapMapper routeLikeMapMapper;
    @Autowired(required = false)
    LikeMapper likeMapper;

    //信息点赞
    public int like(Like like){
        List<Like> routeLikeMaps = likeMapper.selectLikeByMessageIdAndUserId(like.getMessageId(),like.getUserId());
        if(routeLikeMaps.size()==0 || routeLikeMaps==null){
            int result = likeMapper.Like(like);
            return result;
        }else{
            return 0;
        }
    }

    //取消点赞
    public int deleteLike(String messageId,String userId){
        int result = likeMapper.deleteLike(messageId,userId);
        return result;
    }

    //查询点赞    根据信息id 用户id
    public int selectLikeByMessageIdAndUserId(String messageId, String userId){
        List<Like> routeLikeMaps = likeMapper.selectLikeByMessageIdAndUserId(messageId,userId);
        int result;
        if(routeLikeMaps.size()==0||routeLikeMaps==null){
            result=0;
        }else{
            result=1;
        }
        return result;
    }

    //查询点赞数    根据信息id
    public int selectLikeByMessageId(String messageId){
        int result = likeMapper.selectLikeByMessageId(messageId);
        return result;
    }

    //查询点赞 根据用户id
    public List<Like> selectLikeByUserId(String userId){
        return likeMapper.selectLikeByUserId(userId);
    }
}
